package artid.com.arttogo.adapter;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.AuctionLotListParser;
import artid.com.arttogo.utils.MyBitmapImageViewTarget;
import artid.com.arttogo.utils.NetUtils;
import artid.com.arttogo.view.DynamicHeightImageView;

/**
 *
 *
 * 项目名称：ArtworkArt   
 * 类名称：AuctionSpecialInfo_Adapter   
 * 类描述：拍卖行-专场详情适配器   
 * 创建人：耿卫斌   
 * 创建时间：2017-3-1 下午5:10:56   
 *
 */
public class AuctionSpecialInfo_Adapter extends BaseAdapter {
    private Context mContext;
    private List<AuctionLotListParser.AuctionLotList_Lotinfo> list;

    public AuctionSpecialInfo_Adapter(Context mContext,
                                      List<AuctionLotListParser.AuctionLotList_Lotinfo> list) {
        super();
        this.mContext = mContext;
        this.list = list;
    }

    public void notifyData(List<AuctionLotListParser.AuctionLotList_Lotinfo> list) {
        // TODO Auto-generated method stub
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder = null;
        View v = convertView;
        if (v == null) {
            holder = new ViewHolder();
            v = LayoutInflater.from(mContext).inflate(R.layout.item_auctionspecialinfo, null);
            holder.img=(DynamicHeightImageView) v.findViewById(R.id.itemAuctionspecialinfo_img);
            holder.isKeepOnRecord=(ImageView) v.findViewById(R.id.itemAuctionspecialinfo_isKeepOnRecord);
            holder.describe=(TextView) v.findViewById(R.id.itemAuctionspecialinfo_describe);
            holder.number=(TextView) v.findViewById(R.id.itemAuctionspecialinfo_number);
            holder.isNote=(ImageView) v.findViewById(R.id.itemAuctionspecialinfo_note);
            holder.price=(TextView) v.findViewById(R.id.itemAuctionspecialinfo_price);
            holder.company=(TextView) v.findViewById(R.id.itemAuctionspecialinfo_company);
            holder.address=(TextView) v.findViewById(R.id.itemAuctionspecialinfo_address);
            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();
        }
        holder.img.isRightAngle=true;
        holder.img.setHeight(list.get(position).getHeight());
        Glide.with(mContext).load(list.get(position).getImgurl()
                + "_"+ (Integer.parseInt(NetUtils.getDisplayMetrics((Activity)mContext).get(NetUtils.DM_WIDTH)) /2) + "x10.png"
        ).asBitmap().centerCrop().placeholder(R.drawable.ic_menu_rotate).error(R.drawable.ic_menu_rotate).into(new MyBitmapImageViewTarget(holder.img));
        if("0".equals(list.get(position).getIs_record())){
            //0 未备案
            holder.isKeepOnRecord.setVisibility(View.GONE);
        }else if("1".equals(list.get(position).getIs_record())){
            //1已备案
            holder.isKeepOnRecord.setVisibility(View.VISIBLE);
        }
        if(!TextUtils.isEmpty(list.get(position).getLot_author())) {
            holder.describe.setText(list.get(position).getLot_author()+"/" + list.get(position).getLot_name());
        }else{
            holder.describe.setText(list.get(position).getLot_name());
        }
        holder.number.setText("LOT:"+list.get(position).getChart_num());
        int isNoTe=list.get(position).getIs_note();
        switch (isNoTe) {
            case 0:
                //0未记笔记
                holder.isNote.setVisibility(View.GONE);
                break;
            case 1:
                //1为记过笔记
                holder.isNote.setVisibility(View.VISIBLE);
                break;

            default:
                break;
        }
        holder.price.setText(list.get(position).getUnit()+" "+list.get(position).getLot_price());
        holder.company.setText(list.get(position).getSeller_name());
        holder.address.setText(list.get(position).getAddress());
        return v;
    }
    class ViewHolder {
        DynamicHeightImageView img;
        ImageView isKeepOnRecord,isNote;
        TextView describe,number,price,company,address;
    }
}
